package com.liu.common.entity;

import com.liu.common.entity.enums.ResponseEnum;
import lombok.Data;

import java.io.Serializable;

@Data
public class R<V> implements Serializable {

    private Integer code;

    private String msg;

    private V data;

    public R(Integer code, String msg, V data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public R(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * [操作成功 无返回数据]
     * @return R<V>
     */
    public static <V> R<V> success() {
        return new R<>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg());
    }

    /**
     * [操作成功 有返回数据]
     * @param data 返回的数据体
     * @return R<V>
     */
    public static <V> R<V> success(V data) {
        return new R<>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg(), data);
    }

    /**
     * [操作失败]
     * @return R<V>
     */
    public static <V> R<V> failed() {
        return new R<>(ResponseEnum.Failed.getCode(), ResponseEnum.Failed.getMsg());
    }
    
}
